class Solution {
public:
  vector<int> searchRange(vector<int>& nums, int target) {

    vector<int> ans;
    ans.assign(2, -1);

    if(!nums.empty()){
      int left = 0;
      int right = nums.size();
      while(left < right){
        int mid = left + (right - left) / 2;
        if(nums[mid] >= target){
          right = mid;
        }else{
          left = mid + 1;
        }
      }
      if(left >= nums.size() || nums[left] != target){
        return ans;
      }

      ans[0] = left;

      left = 0;
      right = nums.size();
      while(left < right){
        int mid = left + (right - left) / 2;
        if(nums[mid] <= target){
          left = mid + 1;
        }else{
          right = mid;
        }
      }
      ans[1] = right - 1;
    }

    return ans;

  }
};